﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcProject.Models.MaterialUseRecord>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    成本核算
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        成本核算</h2>
    <% using (Html.BeginForm())
       {%>
    <%: Html.ValidationSummary(true) %>
        <%: Html.Label(ViewData["projectName"] as string)%>
        <%: Html.Label(ViewData["teamName"] as string)%>
    <fieldset>
        <legend>成本核算信息</legend>
        <table id="table_calc">
            <tr>
                <th>
                    定额编号
                </th>
                <th>
                    定额名称
                </th>
                <th>
                    工程量
                </th>
                <th>
                    人工费
                </th>
                <th>
                    材料费
                </th>
                <th>
                    机械费
                </th>
                <th>
                    管理费
                </th>
                <th>
                    利润
                </th>
            </tr>
            <tr>
                <td>
                    <%: Html.TextBoxFor(model => model.RatedId, new {@style="display:none" })%>
                    <input type="text" name="txtRatedCode" id="txtRatedCode"/>
                </td>
                <td>
                
                    <%: Html.TextBoxFor(model => model.RatedName, new { @readonly = "readonly"})%>
                    <%: Html.ValidationMessageFor(model => model.RatedName)%>
                </td>
                <td>
                    <%: Html.TextBoxFor(model => model.Project_volume, new { @onkeyup=@"value=value.replace(/[^\d\.]/g,'')" ,@onbeforepaste=@"clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d\.]/g,''))"})%>
                    <%: Html.ValidationMessageFor(model => model.Project_volume) %>
                </td>
                <td>
                    <%: Html.TextBoxFor(model => model.Labor_costs, new { @onkeyup = @"value=value.replace(/[^\d\.]/g,'')", @onbeforepaste = @"clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d\.]/g,''))" })%>
                    <%: Html.ValidationMessageFor(model => model.Labor_costs) %>
                </td>
                <td>
                    <%: Html.TextBoxFor(model => model.Materials_costs, new { @onkeyup = @"value=value.replace(/[^\d\.]/g,'')", @onbeforepaste = @"clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d\.]/g,''))" })%>
                    <%: Html.ValidationMessageFor(model => model.Materials_costs) %>
                </td>
                <td>
                    <%: Html.TextBoxFor(model => model.Machinery_costs, new { @onkeyup = @"value=value.replace(/[^\d\.]/g,'')", @onbeforepaste = @"clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d\.]/g,''))" })%>
                    <%: Html.ValidationMessageFor(model => model.Machinery_costs) %>
                </td>
                <td>
                    <%: Html.TextBoxFor(model => model.Management_Fee, new { @onkeyup = @"value=value.replace(/[^\d\.]/g,'')", @onbeforepaste = @"clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d\.]/g,''))" })%>
                    <%: Html.ValidationMessageFor(model => model.Management_Fee) %>
                </td>
                <td>
                    <%: Html.TextBoxFor(model => model.Profit, new { @onkeyup = @"value=value.replace(/[^\d\.]/g,'')", @onbeforepaste = @"clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d\.]/g,''))" })%>
                    <%: Html.ValidationMessageFor(model => model.Profit) %>
                </td>
            </tr>
        </table>
        <p>
            <input type="submit" value="创建" />
        </p>
    </fieldset>
    <% } %>
    <div>
        <%: Html.ActionLink("返回列表", "Index") %>
    </div>
    <script type="text/javascript">
        $(function () {
            $('#table_calc input').css("width", "50px");
            $('#RatedName').css("width", "150px");
            $('#btnNew').click(function () {
            });
            $('#txtRatedCode').blur(function (e) {
                if ($('#txtRatedCode').val() == '') return;
                $.ajax({
                    type: "POST",
                    contentType: "application/json",
                    url: "../Services/FormCheck.asmx/GetRatedNameByRatedCode",
                    data: "{ratedCode:'" + $('#txtRatedCode').val() + "'}",
                    dataType: "json",
                    success: function (result) {
                        if (result.d) {
                            var v = result.d.split('#');
                            $('#RatedName').val(v[1]);
                            $('#RatedId').val(v[0]);
                            $('#Project_volume').focus();
                        }
                        else {
                            alert('没有该定额号！');
                            $('#RatedName').val('');
                            $('#RatedId').focus();
                        }
                    },
                    error: function (result) {
                        alert(result.responseText);
                    }
                });
            });
            $('#btnCalc').click(function () {
                var Project_volume = $('#Project_volume').val();
                var Labor_costs = $('#Labor_costs').val();
                var Materials_costs = $('#Materials_costs').val();
                var Machinery_costs = $('#Machinery_costs').val();
                var Management_Fee = $('#Management_Fee').val();
                var Profit = $('#Profit').val();
                var single_costs = parseFloat(Labor_costs) + parseFloat(Materials_costs) + parseFloat(Machinery_costs) + parseFloat(Management_Fee);
                var total_costs = parseFloat(Project_volume) * single_costs;
                $('#txtSingle_costs').val(single_costs);
                $('#txtTotal_costs').val(total_costs);
            });
        });
    </script>
</asp:Content>
